<!DOCTYPE html>
<html>
<head>
	<?php
	include "connection-provider.php";
	session_start();
?>
</head>
<body>

<div style="width:960px; margin:0 auto;">



<?php
	
		if(isset($_POST['selectTypeAdmin']))
		{
			$_SESSION['adminQuestionType'] = $_POST['selectTypeAdmin'];
		}
		else
		{
			$_SESSION['adminQuestionType'] = $_GET['selectType'];
		}
		
		$typeId = $_SESSION['adminQuestionType'];
		$result = mysqli_query($con,"SELECT * FROM question_type WHERE QTypeID='$typeId'");	
					while($row = mysqli_fetch_array($result))
					{
						$userName = $row['QType'];
					}
	

?>


	<fieldset>

Change the Type of Question. <a href="select-question-type-admin.php">Click Here</a> <br/>
	
	<br/>
	<?php
	
	/*
	*
	*	For Successful / UnSuccessful messages.
	*
	*/
	
	if(isset($_GET['isAdded']) && $_GET['isAdded']=="yes")
		{
			echo "<font color='blue'>Added Successfully!</font><br/>";
		}
	if(isset($_GET['isEmpty']))
		{
			echo "<font color='red'>All Fields are mendatory</font><br/>";
		}
	if(isset($_GET['isEmptyCheck']))
		{
			echo "<font color='red'>Select the correct answer</font><br/>";
		}
	if(isset($_GET['isUpdated']) && $_GET['isUpdated']=="yes")
		{
			echo "<font color='blue'>Updated Successfully</font><br/>";
		}
	if(isset($_GET['isDeleted']) && $_GET['isDeleted']=="yes")
		{
			echo "<font color='blue'>Deleted Successfully</font><br/>";
		}


		
?>
	<br/>Add Questions to <?php echo $userName; ?>
	
			<!-- ***************** Question type Chceck it *************** -->
			<!-- ***************** Question type Chceck it *************** -->
			<!-- ***************** Question type Chceck it*************** -->
	
	<?php
	/*
		$tableType = "question_type";
		if(isset($_POST['questionOptionName']))
		{
			$typeId = $_POST['questionOptionName'];
			$result = mysqli_query($con,"SELECT * FROM `$tableType` WHERE QTypeID='$typeId'");		
			while($row = mysqli_fetch_array($result))
				{
					echo $row['QType'];
				}
		}
	*/
	
	
	/*
	*
	*	For Adding / Updating New question
	*
	*/
	
	?>

	<br/><br/>
		<form action="database-route.php" method="POST">
			<textarea placeholder="No need to write Question Number" style="resize:vertical" cols="120" 
			name="questionTextArea" 			
			><?php 			
			if(isset($_GET['isEmpty']))
				{
					if(!empty($_GET['question']))
						{
						echo $_GET['question'];			
						}			
				} 	
				
	/*
	*
	*	$_GET['hiddenQuestionId']  is question no. -----from edit / delete
	*
	*/
				
				
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysqli_query($con,"SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysqli_fetch_array($result))
					{	
						echo $row['question'];
					}
			}
			?></textarea> 	<br/><br/>			
			
			<input type="radio" name="optionRadio" value="optionOne">
			A. <input placeholder="Select radio button for correct option" type="text" size="68" name="optionOne" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
			{
				if(!empty($_GET['one']))
				{
				echo $_GET['one'];			
				}			
			}
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysqli_query($con,"SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysqli_fetch_array($result))
					{	
						echo $row['optionOne'];
					}
			}
			?>">
			
			<input type="radio" name="optionRadio" value="optionTwo">
			B. <input placeholder="Select radio button for correct option" type="text" size="68" name="optionTwo" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['two']))
				{
				echo $_GET['two'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysqli_query($con,"SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysqli_fetch_array($result))
					{	
						echo $row['optionTwo'];
					}
			}
			?>">
			
			<br/><br/>
			
			<input type="radio" name="optionRadio" value="optionThree">
			C. <input placeholder="Select radio button for correct option" type="text" size="68" name="optionThree" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['three']))
				{
				echo $_GET['three'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysqli_query($con,"SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysqli_fetch_array($result))
					{	
						echo $row['optionThree'];
					}
			}
			?>">			
			
			<input type="radio" name="optionRadio" value="optionFour">
			D. <input placeholder="Select radio button for correct option" type="text" size="68" name="optionFour" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['four']))
				{
				echo $_GET['four'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysqli_query($con,"SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysqli_fetch_array($result))
					{	
						echo $row['optionFour'];
					}
			}
			?>">				
			<br/><br/>
			<p align="right">
			<input type="hidden" name="hiddenQuestionId" value="
			<?php
				if(isset($_GET['hiddenQuestionId']))
					{
						echo $_GET['hiddenQuestionId'];
					}			
			?>">
			
			
			<input type="hidden" name="hiddenId" value="<?php echo $typeId; ?>">
			<input type="hidden" name="hiddenUserName" value="<?php echo $userName; ?>">
<?php
			if(isset($_GET['hiddenQuestionId']))
				{
					echo "<input type='submit' name='questionUpdateButton' value='Update'>";
				}
			else
				{
					echo "<input type='submit' name='questionSubmitButton' value='Save'>";
				}
?>

				<input type="reset" name="reset" value="Reset">
				
			</p>
		</form>
	
	
	
	
	
	<form action="" method="GET">
		
<?php	
			
			/*
			*
			*	To Display the added questions
			*
			*/
			
			
			$result = mysqli_query($con,"SELECT * FROM question_table WHERE typeId='$typeId'");		
			while($row = mysqli_fetch_array($result))
				{	
					echo $row['questionNumber'] . ".";
					echo "<b>" . $row['question'] . "</b><br/>" ;
					echo "a. " . $row['optionOne'] . "<br/>" ;
					echo "b. " . $row['optionTwo'] . "<br/>" ;
					echo "c. " . $row['optionThree'] . "<br/>" ;
					echo "d. " . $row['optionFour'] . "<br/>" ;
					echo "<b>Correct Answer : </b>" . $row['correctAnswer'] . "<br/><br/>" ;
					echo "<input type='hidden' name='hiddenQuestionId' value='$row[questionNumber]'>";
					echo "<a href='add-question.php?hiddenQuestionId=$row[questionNumber]&selectType=$typeId'>Edit</a>&nbsp;&nbsp;&nbsp;
						<a href='database-route.php?&delete=yes&deleteQuestionId=$row[questionNumber]&selectType=$typeId'>Delete</a>" . "<br/><br/>" ;
				}
				
?>		
				
	</form>


	</fieldset>



</div>
</body>
</html>